<template>
  <view class="address-input">
	<!-- <view class="address-from send" v-if="addressFrom == 'send' && type == 'sendStart'">发</view>
	<view class="address-from receive" v-if="addressFrom == 'receive' && type == 'sendEnd'">送</view>
	
	<view class="address-from send buy" v-if="addressFrom == 'send' && type == 'buyStart'">买</view>
	<view class="address-from receive buy" v-if="addressFrom == 'receive' && type == 'buyEnd'">收</view> -->
    <view :class="'detail-box ' + type" >
      <view class="info-box">
        <view class="address-desc" v-if="!addressInfo2.adress">{{addressDesc}}</view>
        <view class="address-box " v-else>
          <view class="address ellipsis">{{addressInfo2.adress + ' ' + addressInfo2.detail}}[默认]</view>
          <view class="user ellipsis">{{addressInfo2.name + ' ' + addressInfo2.phone}}</view>
        </view>
      </view>
      <view class="mf-right-btn" @click="goSelect">点击获取地址&gt;</view>
     
	  
	 <!-- <view class="address-tag" v-if="addressTag && showTag" @click="selectAddressTag">
	  	<view class="triangle"><text class="icon iconfont">&#xe792;</text></view>
	  	<view class="address">
	  		<view class="desc ellipsis">{{ addressTag.adress + addressTag.detail }}</view>
	  		<view class="desc ellipsis">{{ addressTag.name + ' ' + addressTag.phone }}</view>
	  	</view>
	  	<view class="cancel-btn" @click.stop="closeAddressTag"><text class="icon-chahao iconfont"></text></view>
	  </view> -->
    </view>
  </view>
</template>

<script>
import common from '../../../utils/common.js'
var app = getApp()
export default {
  name: 'AddressInputSend',
  data () {
    return {
		showTag: true
	}
  },
  props: ['addressDesc', 'type', 'addressInfo2', 'addressFrom', 'addressTag', 'showAddressTag'],
  watch: {
	  showAddressTag: {
		  immediate: true,
		  handler: function (val) {
			  this.showTag = val
		  }
	  }
  },
  mounted () {
		if (!app) {
			app = getApp()
		}
  },
  methods: {
	  closeAddressTag() {
		  this.showTag = false
	  },
	  selectAddressTag () {
		  this.$emit('selectAddressTag')
	  },
    goSelect () {
      if (this.isSend()) {
		uni.navigateTo({
			url: '/pages/runErrands/selectAddress'
		})
      }
    },
    goAdd () {
      if (this.isSend()) {
        app.globalData.addressInput = this.addressInfo
		uni.navigateTo({
			url: '/pages/runErrands/addAddress?back=1'
		})
      }
    },
    isSend () {
		if (!app.globalData.is_login) {
			this.$emit('checkLogin')
			return
		}
		app.globalData.addressType = this.type
		this.isHaveCityId()
		return true
		/*if (this.type == 'sendEnd' && app.globalData.sendStart == '') {
		  uni.showToast({
		  	title: common.changeTxt('请先填写发件地址'),
			icon: 'none'
		  })
		  return false
		} else {
		  app.globalData.addressType = this.type
		  this.isHaveCityId()
		  return true
		}*/
    },
    isHaveCityId () {
      if (this.type == 'sendStart') {
        app.globalData.addressCityId = app.globalData.sendEnd != '' ? app.globalData.sendEnd.city : ''
      }

      if (this.type == 'sendEnd') {
        app.globalData.addressCityId = app.globalData.sendStart.city
      }

      if (this.type == 'buyStart') {
        app.globalData.addressCityId = app.globalData.buyEnd != '' ? app.globalData.buyEnd.city : ''
      }

      if (this.type == 'buyEnd') {
        app.globalData.addressCityId = app.globalData.buyStart != '' ? app.globalData.buyStart.city : ''
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.address-input
	padding: 0 20upx 0 70upx !important
	box-sizing border-box !important
	background-position 24upx center !important
	background-repeat no-repeat !important
	background-image url("") !important
	background-size 28upx 34upx !important
	border-bottom 1px solid #969696
.ellipsis
	white-space nowrap
	text-overflow ellipsis
	overflow hidden
.address-input
	background #fff
	font-size 14px
	display flex
	align-items center
	.address-from
		line-height 50upx
		width 50upx
		height 50upx
		background-color #f60
		color #fff
		border-radius 50%
		font-size 12px
		text-align center
		&.receive
			background-color #282828
			color #fff
		&.buy.receive
			color #fff
			white-space nowrap
	.detail-box
		width -webkit-calc(100% - 30px)
		width calc(100% - 30px)
		height 114upx
		display flex
		flex-grow 1
		align-items center
		justify-content space-between
		position relative
		.mf-right-btn
			color #f60
		&.buyStart, &.buyEnd
			border-bottom none
		.info-box
			margin-right 15px
			line-height 1.8
			.address-box
				.address
					color #333
		.right-btn
			background #f60
			color #fff
			padding 4px 10px
			border-radius 5px
			margin 15px 0 15px 15px
		.address-tag
			position absolute
			left 80px
			background #666
			color #fff
			font-size 12px
			line-height 1.4
			display flex
			align-items center
			.triangle
				color #666
				position absolute
				left -12px
				.icon
					font-size 20px
			.address
				padding 7px 0 7px 10px
				.desc
					width 115px
			.cancel-btn
				padding 7px 10px
</style>
